package com.jandan.ui.client;

import java.util.List;

import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.form.Label;
import com.gwtext.client.widgets.layout.FitLayout;
import com.gwtext.client.widgets.layout.VerticalLayout;
import com.jandan.ui.model.CnAndSentence;
import com.jandan.ui.model.LearnedWord;
import com.jandan.ui.model.Word;

public class LearnedWordWindow extends Window {
	private Word word;
	private Panel panel;

	public LearnedWordWindow(LearnedWord learnedWord) {
		this.word = learnedWord.getWord();
		this.setLayout(new FitLayout());
		this.setTitle(word.getWordEn());

		this.setClosable(true);
		this.setWidth(300);
		this.setHeight(300);
		this.setPlain(true);
		this.setCloseAction(Window.HIDE);
		
		createComponent();
	}

	private void createComponent() {
		// 单词Label
		panel = new Panel();		
		panel.setLayout(new VerticalLayout(10));
		panel.setPaddings(10, 10, 0, 0);
		
		Label wordEn = new Label(word.getWordEn());
		panel.add(wordEn);

		// 音标Label
		Label phonetics = new Label(word.getPhonetics());
		phonetics.addClass("phonetics");
		panel.add(phonetics);
		
		List<CnAndSentence> cnAndSentenceList = word.getCnAndSentenceList();
		CnAndSentence cs = null;
		Label cn = null;
		String s = null;
		String e = null;
		Label sentence = null;
		Label ex = null;
		for(int i = 0,n = cnAndSentenceList.size();i < n;i++){
			// 中文含义了英文例句
			cs = cnAndSentenceList.get(i);
			cn = new Label(cs.getCn());
			panel.add(cn);

			s = cs.getSentence();

			if (s != null && s.trim().length() > 0
					&& !s.trim().equalsIgnoreCase("none")) {
				sentence = new Label(s);
				panel.add(sentence);
			}
		}
		
		e = word.getDescription();
		if(e != null && e.trim().length() > 0) {
			ex = new Label(e);			
			panel.add(ex);
		}

		this.add(panel);
	}
}
